package net.xiangcaowuyu.cacheredis.controller;

import net.xiangcaowuyu.cacheredis.entity.User;
import net.xiangcaowuyu.cacheredis.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author laughing
 * @date 2020-10-10
 */
@RestController
public class UserController {

     private final UserService userService;

     public UserController(UserService userService){
         this.userService=userService;
     }

    /**
     * 根据Id查找用户
     * @return 用户
     */
    @RequestMapping("findUserById")
    public User findUserById(){
        return userService.findUserById(1);
    }

    /**
     * 根据Id更新用户信息
     * @return 用户
     */
    @RequestMapping("updateUserById")
    public User updateUserById(){
      User  user = userService.findUserById(1);
        user.setName("李四");
      return  userService.updateUserById(user);
    }

    /**
     * 根据Id删除用户
     */
    @RequestMapping("deleteUserById")
    public void deleteUserById(){
        userService.deleteUserById(1);
    }

}
